package alex.deploy.controller;

import alex.deploy.controller.qo.ProjectQO;
import alex.deploy.model.Project;
import alex.deploy.repository.ProjectRepository;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.logging.Logger;

/**
 * Created by lushun.chen on 2017/4/26.
 *
 * @author lushun.chen
 */
@Controller
@RequestMapping("project")
public class ProjectController {

    private final static org.slf4j.Logger logger = LoggerFactory.getLogger(ProjectController.class);

    @Resource
    ProjectRepository projectRepository;

    @RequestMapping("table")
    public String index(ModelMap modelMap, ProjectQO projectQO) {
        logger.error("l:{},u:{},L:{}", 1, 4, 6);
        Pageable pageable = new PageRequest(projectQO.getPage(), projectQO.getSize(), new Sort(Sort.Direction.ASC, "id"));
        Page<Project> page = projectRepository.findByName(projectQO.getName() == null ? "%" : "%" + projectQO.getName() + "%", pageable);
        modelMap.put("page", page);
        return "project_table";
    }

    @RequestMapping("save")
    public String save(ModelMap modelMap) {
        return "";
    }

    @RequestMapping("save_index")
    public String saveIndex(ModelMap modelMap) {
        return "project_save";
    }

    @RequestMapping("update")
    public String update(ModelMap modelMap) {
        return "";
    }

    @RequestMapping("delete")
    public String delete(ModelMap modelMap) {
        return "";
    }
}
